﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FytSoa.Service.DtoModel;
using FytSoa.Service.Interfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using FytSoa.Common;
using FytSoa.Core.Model;

namespace FytSoa.Api.Areas.Circle.Controllers
{
    [Route("api/circle/[controller]")]
    [ApiController]
    public class IndexController : ControllerBase
    {
        private readonly ISysCodeService _codeService;
        private readonly ICmsSiteService _siteService;
        private readonly ICmsAdvListService _advService;
        private readonly ICmsArticleService _articleService;
        public IndexController(ISysCodeService codeService,
            ICmsSiteService siteService,
            ICmsAdvListService advService
            , ICmsArticleService articleService)
        {
            _codeService = codeService;
            _siteService = siteService;
            _advService = advService;
            _articleService = articleService;
        }

        [HttpPost("data")]
        public async Task<IActionResult> GetHome()
        {
            //当前站点
            var siteModel = await _siteService.GetModelAsync(m => m.Guid == "cf15bf0a-d8b1-4643-9dfe-8601b5bd2299");
            //首页栏位
            var columnList = await _codeService.GetListAsync(m=>m.ParentGuid== "ab5223c1-4d69-44ec-b49f-c7a0c9db908f" && m.Status,m=>m.Sort,Common.DbOrderEnum.Asc);
            //首页轮播图
            var advList = await _advService.GetListAsync(m=>m.ClassGuid== "e8b4325d-bdd8-448f-83be-034d66642b14" && m.Status,m=>m.Sort,Common.DbOrderEnum.Desc);
            //查询第一页的新闻
            var param=new PageParm(){id=1080,audit=0,types=1,attr=1,limit=20};
            var articleList=await _articleService.WxAppPage(param);
            var model = new CircleIndexDto() {
                site=siteModel.data,
                code=columnList.data,
                adv=advList.data,
                list=articleList.data
            };
            var res=new ApiResult<CircleIndexDto>(){
                data=model
            };
            return Ok(res);
        }

        [HttpPost("article")]
        public async Task<IActionResult> GetArticlePage([FromBody]PageParm param)
        {
            if (param.id==0)
            {
                param.id=1080;                
            }
            param.audit = 0;
            param.types = 1;
            return Ok(await _articleService.WxAppPage(param));
        }

        [HttpPost("article/info")]
        public async Task<IActionResult> GetArticlePage([FromBody]ParmInt param)
        {
            return Ok(await _articleService.GetModelAsync(m=>m.Id==param.id));
        }

        
        [HttpPost("bl/index")]
        public async Task<IActionResult> GetBaoLiaoIndex()
        {
            //首页爆料轮播图
            var advList = await _advService.GetListAsync(m=>m.ClassGuid== "60dda477-3887-4f4b-a705-820d292ed790" && m.Status,m=>m.Sort,Common.DbOrderEnum.Desc);
            //查询第一页的新闻
            var param=new PageParm(){id=1080,audit=0,types=1,attr=1,limit=20};
            var articleList=await _articleService.WxAppPage(param);
            var model = new CircleIndexDto() {
                adv=advList.data,
                list=articleList.data
            };
            var res=new ApiResult<CircleIndexDto>(){
                data=model
            };
            return Ok(res);
        }

        
    }
}